package de.gameduell.framework.application.view {

	import de.gameduell.framework.application.Window;
	import de.gameduell.framework.application.controller.Controller;
	import de.gameduell.framework.gui.popup.Popup;
	import de.gameduell.framework.queue.SingleActionQueue;
	import de.gameduell.net.src.communication.CommunicationEvent;

	import flash.events.Event;
	import flash.events.MouseEvent;

	public class MultiplayerView extends SimpleView{
		protected var actionQueue:SingleActionQueue;
		protected var abortPopup:Popup;
		protected var reconnectPopup:Popup;

		public function MultiplayerView(aWindow:Window, aController:Controller){
			actionQueue = SingleActionQueue.getInstance();
			super(aWindow,aController);
		}
		
		override protected function initView():void{
			super.initView();
			abortPopup = new Popup("AbortGamePopup", "AbortGamePopup", 0, true);
			abortPopup.registerButton("abort", abortGame);
			abortPopup.registerButton("cancel", cancelAbortGame);
			abortPopup.modal = true;
			closeButton.removeEventListener(MouseEvent.CLICK, abortGame);
			closeButton.addEventListener(MouseEvent.CLICK, abortPopup.show);
			
			reconnectPopup = new Popup("ReconnectPopup", "ReconnectPopup", 0, true);
			baseController.addEventListener(CommunicationEvent.RECONNECT, onReconnect);
			baseController.addEventListener(CommunicationEvent.RECONNECTED, onReconnected);
		}
		
		protected function onReconnect(event:CommunicationEvent):void {
			reconnectPopup.show();
		}
		
		protected function onReconnected(event:CommunicationEvent):void {
			reconnectPopup.hide();
		}
		
		protected function onAbort(event:MouseEvent):void {
			abortPopup.show();
		}
		
		protected function cancelAbortGame(event:Event):void {
			abortPopup.hide();
		}
	}
}
